package com.lazy.utils.datasource;

/**
 * 本地线程，数据源上下文
 * @author lcx
 *
 */
public class DataSourceContextHolder {

    /**
     * 线程本地环境
     */
	private static final ThreadLocal<String> THREAD_LOCAL = new ThreadLocal<>();

    public static ThreadLocal<String> getLocal() {
        return THREAD_LOCAL;
    }

    /**
     * 读库
     */
    public static void setSlave() {
        THREAD_LOCAL.set(DataSourceTypeEnum.slave.getType());
    }

    /**
     * 主库
     */
    public static void setMaster() {
        THREAD_LOCAL.set(DataSourceTypeEnum.master.getType());
    }

    public static String getMasterOrSlave() {
        return THREAD_LOCAL.get();
    }
    
    public static void clear(){
        THREAD_LOCAL.remove();
    }

}
